package com.yuanduan.mplus.presenter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yuanduan.mplus.R;
import com.yuanduan.mplus.model.entity.PointEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cj on 2016/6/14.
 * Email:781806481@qq.com
 */
public class PointListViewAdapter extends BaseAdapter {
    private  Context mContext;
    private List<PointEntity> datalists=new ArrayList<PointEntity>();

    public PointListViewAdapter(Context context){
        mContext=context;
    }
    @Override
    public int getCount() {
        return datalists.size();
    }

    @Override
    public Object getItem(int position) {
        return datalists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PointEntity entity= (PointEntity) getItem(position);
        View view;
        ViewHolder viewHolder;
        if(convertView==null){
            view= LayoutInflater.from(mContext).inflate(R.layout.point_listview_item,null);
            viewHolder=new ViewHolder();
            viewHolder.tv_addedPoint= (TextView) view.findViewById(R.id.point_listview_detail);
            viewHolder.tv_time= (TextView) view.findViewById(R.id.point_tv_time);
            view.setTag(viewHolder);
        }else{
            view=convertView;
            viewHolder= (ViewHolder) view.getTag();
        }
        viewHolder.tv_time.setText(entity.getTime());
        viewHolder.tv_addedPoint.setText(entity.getAddedPoint());
        return view;
    }

    public void setDatalists(List<PointEntity> lists){
        if(lists==null){
            return;
        }
        for(int i=0;i<lists.size();i++){
            datalists.add(lists.get(i));
        }
        notifyDataSetChanged();
    }
    class ViewHolder{
        TextView tv_addedPoint;
        TextView tv_time;
    }
}
